﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>报关管理</title>
<link rel="stylesheet"
	href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script
	src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script
	src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		//单选复选
		var flag = true;
		$("#selectAll").click(function() {

			if (this.checked) {
				$("#fu:checkbox,selectAll").prop("checked", true);
			} else {
				$("#fu:checkbox,selectAll").prop("checked", false);
			}
		});

		$(".s1").click(function() {
			var obj = $(".s1");
			var flag = true;
			obj.each(function() {
				if (!$(this).is(":checked")) {
					flag = false;
					return false;
				}
			});
			if (flag == true) {
				$("#selectAll").prop("checked", true);
			} else {
				$("#selectAll").prop("checked", false);
			}

		});
		
		//新增一条保存
		$("#add").click(function(){
			
			$.ajax({
				type:'post',
				url:'<%=basePath%>customs/addcustoms',
				data:$("#form").serialize(),
 				dataType:"text",
				success:function(data){
					window.location.reload();
				}
			});
						
			});	
	});
	
	//修改
function edit(ID){
			 top.jzts();
		        var diag = new top.Dialog();
		        diag.Drag = true;
		        diag.Title = "报关方式";
		        diag.URL = '<%=basePath%>customs/edit?id=' + ID;
		        diag.Width = 550;
		        diag.Height = 400;
		        diag.CancelEvent = function () { //关闭事件
		        	diag.close();
		        	window.location.reload();	
		            
		        };
		        diag.show();
		}
	
	 //删除
    function  delet(ID){
    	if (confirm("确认要删除本条信息！")){
    		 $.ajax({
 				type:'post',
 				url:'<%=basePath%>customs/deleteU?ID='+ID,
 				success:function(){
 					window.location.reload();
 				}
 			
 			});
    		
    		return false;
    		}
			 
	 }
	 
	 function shan(){

			var trList = [];
var $simpleTabletr = $("#simple-table tbody tr");
var list = {}
for(var i=0,len=$simpleTabletr.length;i<len;i++){
var objTr = $simpleTabletr[i];
var flag = $(objTr).find("td").first().find("label").find(".s1")[0].checked;

if(flag){
	trList.push(objTr);
}
}
//传到后台的data json格式
var data = [];
for(var i=0,size=trList.length;i<size;i++){
var $tds = $(trList[i]).find("td");
//取id
var id = $($tds[0]).find("label").find("input[name='s1']")[0].value;
var item = {};
item.ID = id.trim();

data.push(item)
}
var dataStr = JSON.stringify(data);
if (confirm("确认要删除选中的信息！")){
	$.ajax({
		type: "POST",
		url: '<%=basePath%>customs/deleteInfo',
		data: {dataJsonStr:dataStr},
		cache: false,
		success:function (data) {
			 window.location.reload();
			 
		}
		   });
	
	return false;
	}

}
    
</script>
</head>
<body>

	<form  action="declaration" class="form-horizontal" method="post">
		<fieldset>
			<div
				style="width: 200px; height: 30px; margin: 15px auto; color: #00FFFF; font-size: 25px">报关方式管理</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">报关方式</label>
				<div class="col-sm-4">
					<input class="form-control"  type="text" placeholder="请输入报关方式" 
					name="CUSTOMS_DECLARATION_MODE" value="${pd.CUSTOMS_DECLARATION_MODE}" />
				</div>
				<label class="col-sm-2 control-label">快速检索码</label>
				<div class="col-sm-4">
					<input class="form-control"  type="text" placeholder="请输入检索码" 
					name="FAST_SEARCH_CODE" value="${pd.FAST_SEARCH_CODE}"/>
				</div>
			</div>
		</fieldset>
		<fieldset>
			<div class="form-group">
				<label for="disabledSelect" class="col-sm-2 control-label">是否可用</label>
				<div class="col-sm-10">
					<select class="form-control" name="ENABLE">
					   <option value="">全部</option>
					   
                         <option value="1" 
                                 <c:if test="${pd.ENABLE=='1' }">selected</c:if> >是
                          </option>
                         <option value="0" 
                                 <c:if test="${pd.ENABLE=='0' }">selected</c:if> >否
                         </option>                
						
					</select>
				</div>
			</div>
		</fieldset>
		<div class="form-group"
			style="margin: 0px auto; width: 300px; height: 50px">
			<input style="width: 50px;" type="submit" value="查询"/>  
			<input style="width: 50px;" type="button" data-toggle="modal" data-target="#myModal" value="添加"/> 
			</div>

	</form>
	
		<!-- 点击添加增加的模态框 -->	
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					新增报关管理数据
				</h4>
			</div>
			<div style="width:600px">
	<form id="form" method="post" id = "test">
	
			<fieldset>
			<div class="form-group" >
				<label class="col-sm-2 control-label">报关方式</label>
				<div class="col-sm-4">
					<input class="form-control"  type="text" placeholder="请输入报关方式" 
					name="CUSTOMS_DECLARATION_MODE" value="${pd.CUSTOMS_DECLARATION_MODE}" />
				</div>
				<label class="col-sm-2 control-label">快速检索码</label>
				<div class="col-sm-4">
					<input class="form-control"  type="text" placeholder="请输入检索码" 
					name="FAST_SEARCH_CODE" value="${pd.FAST_SEARCH_CODE}"/>
				</div>
			</div>
		</fieldset>
		<fieldset>
			<div class="form-group">
				<label for="disabledSelect" class="col-sm-2 control-label">是否可用</label>
				<div class="col-sm-10">
					<select class="form-control" name="ENABLE">
					     <option value="1" 
                                 <c:if test="${pd.ENABLE=='1' }">selected</c:if> >是
                          </option>
                         <option value="0" 
                                 <c:if test="${pd.ENABLE=='0' }">selected</c:if> >否
                         </option>                
						
					</select>
				</div>
			</div>
		</fieldset>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
				<button type="button" class="btn btn-primary" id="add">
					保存
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
</form>
	</div>	
	<div>
		<input style="width: 100px;" type="button" value="批量删除" id="del_model" onclick="shan()"/>
	</div>

	<div>
		<table id="simple-table" class="table table-striped table-bordered table-hover">
			<thead>
				<tr>
					<th class="center" style="width: 30px;"><label class="pos-rel">
							<input type="checkbox" id="selectAll"  /> <span class="lbl"></span>
					</label></th>
					<th class="center">报关方式</th>
					<th class="center">快速检索码</th>
					<th class="center">是否可用</th>
					<th class="center">修改</th>
					<th class="center">删除</th>
				</tr>
			</thead>

			<c:forEach items="${list}" var="customs">

				<tr>

					<td class="center" style="width: 30px;"><label
						class="pos-rel"> <input class="s1"  name="s1" type="checkbox" id="fu" value="${customs.ID}"/>
							<span class="lbl"></span></label></td>
					<td class="center">${customs.CUSTOMS_DECLARATION_MODE}</td>
					<td class="center">${customs.FAST_SEARCH_CODE }</td>
					<td class="center"><c:if test="${customs.ENABLE ==1}">
        		                                               是
        </c:if> <c:if test="${customs.ENABLE ==0}">
        		                                               否
        </c:if></td>
					<td class="center"><a onclick="edit('${customs.ID}')">修改</a></td>
					<td class="center"><a onclick="delet('${customs.ID}')">刪除</a></td>

				</tr>
			</c:forEach>
		</table>

	</div>
</body>
</html>